home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / SOUND / PLAY_SRC.ZIP / IO.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-11-22  |  10.0 KB  |  516 lines

  1. .386p
  2. code32    segment para public use32
  3.     assume cs:code32, ds:code32
  4.  
  5. _filebufloc    dd    0        ; location must be in low mem
  6. _filebuflen    dw    4000h
  7.  
  8. public    _filebufloc, _filebuflen
  9. public    _closefile,_createfile,_createhiddenfile,_openfile,_deletefile,_lseekfile
  10. public    _filesize,_readfile,_writefile,_filecopy,_findfile,_renfile
  11.  
  12. extrn    v86r_eax:dword, v86r_ebx:dword, v86r_ecx:dword, v86r_edx:dword
  13. extrn    v86r_esi:dword, v86r_edi:dword, v86r_ebp:dword
  14. extrn    v86r_ah:byte, v86r_al:byte, v86r_bh:byte, v86r_bl:byte
  15. extrn    v86r_ch:byte, v86r_cl:byte, v86r_dh:byte, v86r_dl:byte
  16. extrn    v86r_ax:word, v86r_bx:word, v86r_cx:word, v86r_dx:word
  17. extrn    v86r_si:word, v86r_di:word, v86r_bp:word
  18. extrn    v86r_ds:word, v86r_es:word, v86r_fs:word, v86r_gs:word
  19. extrn    _selcode:word, _seldata:word, _selzero:word, _lomembase:dword
  20. extrn    _lomemtop:dword, _himembase:dword, _himemtop:dword, _pspa:dword
  21. extrn    _code16a:dword, _code32a:dword, _getirqvect:dword, _setirqvect:dword
  22. extrn    _sysbyte0:byte, _irqmode:word
  23.  
  24. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  25. ; Create file
  26. ; In:
  27. ;   EDX -> ASCIIZ filename
  28. ; Out:
  29. ;   CF=1 - Error creating file
  30. ;   CF=0 - File created succesfully
  31. ;     V86R_BX - file handle
  32. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  33. _createfile:
  34.     push ax
  35.     push edx
  36.     add edx,_code32a
  37.     mov ax,dx
  38.     shr edx,4
  39.     and ax,0fh
  40.     mov v86r_dx,ax
  41.     mov v86r_ds,dx
  42.     mov v86r_ax,3c00h
  43.     mov v86r_cx,20h
  44.     mov al,21h
  45.     int 33h
  46.     mov ax,v86r_ax
  47.     mov v86r_bx,ax
  48.     pop edx
  49.     pop ax
  50.     ret
  51.  
  52. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  53. ; Create hidden file
  54. ; In:
  55. ;   EDX -> ASCIIZ filename
  56. ; Out:
  57. ;   CF=1 - Error creating file
  58. ;   CF=0 - File created succesfully
  59. ;     V86R_BX - file handle
  60. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  61. _createhiddenfile:
  62.     push ax
  63.     push edx
  64.     add edx,_code32a
  65.     mov ax,dx
  66.     shr edx,4
  67.     and ax,0fh
  68.     mov v86r_dx,ax
  69.     mov v86r_ds,dx
  70.     mov v86r_ax,3c00h
  71.     mov v86r_cx,02h
  72.     mov al,21h
  73.     int 33h
  74.     mov ax,v86r_ax
  75.     mov v86r_bx,ax
  76.     pop edx
  77.     pop ax
  78.     ret
  79.  
  80. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  81. ; Open file
  82. ; In:
  83. ;   EDX -> ASCIIZ filename
  84. ; Out:
  85. ;   CF=1 - Error opening file
  86. ;   CF=0 - File opened succesfully
  87. ;     V86R_BX - file handle
  88. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  89. _openfile:
  90.     push ax
  91.     push edx
  92.     add edx,_code32a
  93.     mov ax,dx
  94.     shr edx,4
  95.     and ax,0fh
  96.     mov v86r_dx,ax
  97.     mov v86r_ds,dx
  98.     mov v86r_ax,3d02h
  99.     mov al,21h
  100.     int 33h
  101.     mov ax,v86r_ax
  102.     mov v86r_bx,ax
  103.     pop edx
  104.     pop ax
  105.     ret
  106.  
  107. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  108. ; Close a file
  109. ; In:
  110. ;   V86R_BX - file handle
  111. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  112. _closefile:
  113.     push ax
  114.     mov v86r_ax,3e00h
  115.     mov al,21h
  116.     int 33h
  117.     pop ax
  118.     ret
  119.  
  120. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  121. ; Delete a file
  122. ; In:
  123. ;   EDX -> ASCIIZ filename
  124. ; Out:
  125. ;   CF=1 - Error opening file
  126. ;   CF=0 - File opened succesfully
  127. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  128. _deletefile:
  129.     push ax
  130.     push edx
  131.     add edx,_code32a
  132.     mov ax,dx
  133.     shr edx,4
  134.     and ax,0fh
  135.     mov v86r_dx,ax
  136.     mov v86r_ds,dx
  137.     mov v86r_ah,41h
  138.     mov al,21h
  139.     int 33h
  140.     pop edx
  141.     pop ax
  142.     ret
  143.  
  144. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  145. ; Seek position in file
  146. ; In:
  147. ;   V86R_BX - file handle
  148. ;   EAX - signed offset to move to
  149. ;   BL - from: 0-beginning of file, 1-current location, 2-end of file
  150. ; Out:
  151. ;   CF=1  - Error seeking in file
  152. ;     EAX - ?
  153. ;   CF=0  - Seek fine
  154. ;     EAX - new offset from beginning of file
  155. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  156. _lseekfile:
  157.     mov v86r_ah,42h
  158.     mov v86r_al,bl
  159.     mov v86r_dx,ax
  160.     shr eax,16
  161.     mov v86r_cx,ax
  162.     mov al,21h
  163.     int 33h
  164.     pushf
  165.     mov ax,v86r_dx
  166.     shl eax,16
  167.     mov ax,v86r_ax
  168.     popf
  169.     ret
  170.  
  171. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  172. ; Get size of file
  173. ; In:
  174. ;   V86R_BX - file handle
  175. ; Out:
  176. ;   CF=1  - Error checking file
  177. ;     EAX - ?
  178. ;   CF=0  - chek fine
  179. ;     EAX - size of file
  180. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  181. _filesize:
  182.     mov v86r_ax,4201h
  183.     xor eax,eax
  184.     mov v86r_cx,ax
  185.     mov v86r_dx,ax
  186.     mov al,21h
  187.     int 33h
  188.     push v86r_dx
  189.     push v86r_ax
  190.     mov v86r_ax,4202h
  191.     xor eax,eax
  192.     mov v86r_cx,ax
  193.     mov v86r_dx,ax
  194.     mov al,21h
  195.     int 33h
  196.     mov ax,v86r_dx
  197.     shl eax,16
  198.     mov ax,v86r_ax
  199.     pop v86r_dx
  200.     pop v86r_cx
  201.     mov v86r_ax,4200h
  202.     push eax
  203.     mov al,21h
  204.     int 33h
  205.     pop eax
  206.     ret
  207.  
  208. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  209. ; Read from file
  210. ; In:
  211. ;   V86R_BX - file handle
  212. ;   EDX -> buffer to read to
  213. ;   ECX - number of bytes to read
  214. ; Out:
  215. ;   CF=1 - Error reading file
  216. ;     EAX - ?
  217. ;   CF=0 - Read went fine
  218. ;     EAX - number of bytes read
  219. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  220. _readfile:
  221.     pushad
  222.     xor ebp,ebp
  223.     add edx,_code32a
  224.     lea ebx,[ecx+edx]
  225.     cmp ebx,100000h
  226.     ja readlong
  227.     mov eax,edx
  228.     shr eax,4
  229.     and dx,0fh
  230.     mov v86r_ds,ax
  231.     mov v86r_dx,dx
  232. readl:
  233.     mov eax,0fff0h
  234.     cmp eax,ecx
  235.     jbe readlf1
  236.     mov eax,ecx
  237. readlf1:
  238.     mov v86r_cx,ax
  239.     mov v86r_ax,3f00h
  240.     mov al,21h
  241.     int 33h
  242.     jc readdone2
  243.     movzx ebx,v86r_ax
  244.     add ebp,ebx
  245.     sub ecx,ebx
  246.     jbe readdone
  247.     or ebx,ebx
  248.     jz readdone
  249.     add v86r_ds,0fffh
  250.     jmp readl
  251. readlong:
  252.     mov edi,edx
  253.     sub edi,_code32a
  254.     mov edx,ecx
  255.     mov eax,_filebufloc
  256.     add eax,_code32a
  257.     mov ebx,eax
  258.     shr eax,4
  259.     and bx,0fh
  260.     mov v86r_ds,ax
  261.     mov v86r_dx,bx
  262.     movzx ebx,_filebuflen
  263. readlongl:
  264.     mov eax,ebx
  265.     cmp eax,edx
  266.     jbe readlonglf1
  267.     mov eax,edx
  268. readlonglf1:
  269.     mov v86r_cx,ax
  270.     mov v86r_ax,3f00h
  271.     mov al,21h
  272.     int 33h
  273.     jc short readdone2
  274.     movzx ecx,v86r_ax
  275.     add ebp,ecx
  276.     mov eax,ecx
  277.     or eax,eax
  278.     jz readdone
  279.     mov esi,_filebufloc
  280.     rep movsb
  281.     sub edx,eax
  282.     ja readlongl
  283. readdone:
  284.     clc
  285. readdone2:
  286.     mov [esp+28],ebp
  287.     popad
  288.     ret
  289.  
  290. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  291. ; Write to file
  292. ; In:
  293. ;   V86R_BX - file handle
  294. ;   EDX -> buffer to write from
  295. ;   ECX - number of bytes to write
  296. ; Out:
  297. ;   CF=1 - Error writing file
  298. ;     EAX - ?
  299. ;   CF=0 - Write went fine
  300. ;     EAX - number of bytes written
  301. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  302. _writefile:
  303.     pushad
  304.     xor ebp,ebp
  305.     add edx,_code32a
  306.     lea ebx,[ecx+edx]
  307.     cmp ebx,100000h
  308.     ja writelong
  309.     mov eax,edx
  310.     shr edx,4
  311.     and ax,0fh
  312.     mov v86r_ds,dx
  313.     mov v86r_dx,ax
  314. writel:
  315.     mov eax,0fff0h
  316.     cmp eax,ecx
  317.     jbe writelf1
  318.     mov eax,ecx
  319. writelf1:
  320.     mov v86r_cx,ax
  321.     mov v86r_ax,4000h
  322.     mov al,21h
  323.     int 33h
  324.     jc writedone2
  325.     movzx ebx,v86r_ax
  326.     cmp v86r_cx,bx
  327.     jnz writedone3
  328.     add ebp,ebx
  329.     sub ecx,ebx
  330.     jbe writedone
  331.     add v86r_ds,0fffh
  332.     jmp writel
  333. writelong:
  334.     mov esi,edx
  335.     sub esi,_code32a
  336.     mov edx,ecx
  337.     mov eax,_filebufloc
  338.     add eax,_code32a
  339.     mov ebx,eax
  340.     shr eax,4
  341.     and bx,0fh
  342.     mov v86r_ds,ax
  343.     mov v86r_dx,bx
  344.     movzx ebx,_filebuflen
  345. writelongl:
  346.     mov eax,ebx
  347.     cmp eax,edx
  348.     jbe writelonglf1
  349.     mov eax,edx
  350. writelonglf1:
  351.     mov ecx,eax
  352.     mov edi,_filebufloc
  353.     rep movsb
  354.     mov v86r_cx,ax
  355.     mov v86r_ax,4000h
  356.     mov al,21h
  357.     int 33h
  358.     jc writedone2
  359.     movzx ecx,v86r_ax
  360.     cmp v86r_cx,cx
  361.     jnz writedone3
  362.     add ebp,ecx
  363.     sub edx,ecx
  364.     ja writelongl
  365. writedone:
  366.     clc
  367. writedone2:
  368.     mov [esp+28],ebp
  369.     popad
  370.     ret
  371. writedone3:
  372.     stc
  373.     jmp writedone2
  374.  
  375. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  376. ; Copy some bytes from one file to another
  377. ; In:
  378. ;   V86R_SI - source file handle
  379. ;   V86R_DI - destination file handle
  380. ;   ECX - number of bytes to copy
  381. ; Out:
  382. ;   CF=1  - Error copying file
  383. ;     EAX - ?
  384. ;   CF=0  - copied fine
  385. ;     EAX - number of bytes copied
  386. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  387. _filecopy:
  388.     pushad
  389.     xor ebp,ebp
  390.     mov edx,_filebufloc
  391.     add edx,_code32a
  392.     mov al,dl
  393.     and ax,0fh
  394.     shr edx,4
  395.     mov v86r_ds,dx
  396.     mov v86r_dx,ax
  397.     movzx ebx,_filebuflen
  398. copylongl:
  399.     mov eax,ebx
  400.     cmp eax,ecx
  401.     jbe copylonglf1
  402.     mov eax,ecx
  403. copylonglf1:
  404.     mov v86r_cx,ax
  405.     mov v86r_ax,3f00h
  406.     mov ax,v86r_si
  407.     mov v86r_bx,ax
  408.     mov al,21h
  409.     int 33h
  410.     jc copydone2
  411.     mov ax,v86r_ax
  412.     or ax,ax
  413.     jz copydone
  414.     mov v86r_cx,ax
  415.     mov v86r_ax,4000h
  416.     mov ax,v86r_di
  417.     mov v86r_bx,ax
  418.     mov al,21h
  419.     int 33h
  420.     jc copydone2
  421.     movzx edx,v86r_ax
  422.     add ebp,edx
  423.     sub ecx,edx
  424.     ja copylongl
  425. copydone:
  426.     clc
  427. copydone2:
  428.     mov [esp+28],ebp
  429.     popad
  430.     ret
  431.  
  432.  
  433. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  434. ; Do an AH=4E findfirst
  435. ; In:
  436. ;   AL - type of search: 4E-first, 4F-next
  437. ;   CX - search attributes
  438. ;   EDX -> 13 byte buffer for filename found
  439. ;   EDI -> search mask
  440. ; Out:
  441. ;   CX     - Attribute of file
  442. ;   CF=1 - file not found
  443. ;     [EDX] - ?
  444. ;   CF=0 - file found
  445. ;     [EDX] - filename
  446. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  447. _findfile:
  448.     push eax
  449.     push esi
  450.     push edi
  451.     add edi,_code32a
  452.     mov esi,edi
  453.     and esi,0fh
  454.     shr edi,4
  455.     mov v86r_ds,di
  456.     mov v86r_dx,si
  457.     mov v86r_ah,al
  458.     mov v86r_cx,cx
  459.     mov esi,_code16a
  460.     sub esi,62h
  461.     mov edi,edx
  462.     mov al,21h
  463.     int 33h
  464.     mov ecx,_pspa
  465.     movzx cx,byte ptr gs:[ecx+149]
  466.     mov ax,gs
  467.     mov ds,ax
  468.     movsd
  469.     movsd
  470.     movsd
  471.     movsb
  472.     mov ax,es
  473.     mov ds,ax
  474.     pop edi
  475.     pop esi
  476.     pop eax
  477.     ret
  478. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  479. ; Rename a file
  480. ; In:
  481. ;   EDX -> Old FileName  (asciiz)
  482. ;   EDI -> New FileName  (asciiz)
  483. ; Out:
  484. ;   CF=1 - Error
  485. ;    EAX - ErrorCode
  486. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  487. _renfile:
  488.     push edx
  489.     push edi
  490.     push esi
  491.     add edi,_code32a
  492.     mov esi,edi
  493.     and esi,0fh
  494.     shr edi,4
  495.     mov v86r_es,di
  496.     mov v86r_di,si
  497.     mov edi,edx
  498.     add edi,_code32a
  499.     mov esi,edi
  500.     and esi,0fh
  501.     shr edi,4
  502.     mov v86r_ds,di
  503.     mov v86r_dx,si
  504.     mov v86r_ah,56h
  505.     mov al,21h
  506.     int 33h
  507.     pop esi
  508.     pop edi
  509.     pop edx
  510.     movzx eax,v86r_ax
  511.     ret
  512.  
  513. ends
  514. end
  515.  
  516.